package xianchenganquan;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Locksuo implements Runnable{
    private  int tick =100;
    Lock l = new ReentrantLock();
    @Override
    public void   run() {
        while (true){
            l.lock();
                if (tick>0) {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tick --;
                    System.out.println(Thread.currentThread().getName()+"变量"+tick);
                }
                l.unlock();
            }
        }
    }


